/**
 * ipassbook 0.6.0
 * Copyright (C)2009 wateray and contributors
 * wateray@gmail.com
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

package com.wateray.ipassbook.ui.view.contentPanel;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import com.wateray.ipassbook.kernel.event.IPassbookEvent;
import com.wateray.ipassbook.kernel.event.IPassbookObserver;

/**
 * @author wateray
 * @create 2009-5-26
 */
public abstract class AbstractPage extends JPanel implements IPage {

	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = 1L;

	/** default is false. */
	private boolean isDefaultPage;

	/** The buttonBar (JPanel), usually used as buttonBar. */
	protected JPanel buttonBar;

	/**
	 * Layout for this AbstractPage is BorderLayout. <br/>
	 * getTopPane() -- north <br/>
	 * getCenterPane() -- center <br/>
	 * getBottomPane() -- south <br/>
	 * getLeftPane() -- west <br/>
	 * getRightPane() -- ease <br/>
	 * */
	protected AbstractPage() {
		super();

		BorderLayout layout = new BorderLayout();
		this.setLayout(layout);

		//top pane.
		if (getTopPane() != null) {
			this.add(getTopPane(), BorderLayout.NORTH);
		}
		//center pane.
		if (getCenterPane() != null) {
			this.add(getCenterPane(), BorderLayout.CENTER);
		}
        //bottom pane.
		if (getBottomPane() != null) {
			this.add(getBottomPane(), BorderLayout.SOUTH);
		}
		//left pane.
		if (getLeftPane() != null) {
			this.add(getLeftPane(), BorderLayout.WEST);
		}
       //right pane.
		if (getRightPane() != null) {
			this.add(getRightPane(), BorderLayout.EAST);
		}

		// Add IPassbookObserver
		IPassbookObserver.getInstance().addIPassbookListener(this);
	}

	/**
	 * @return buttonBar. layout for this pane is FlowLayout.
	 * */
	protected Component getButtonBar() {
		if (buttonBar == null) {
			buttonBar = new JPanel();
			FlowLayout layou = new FlowLayout(FlowLayout.LEADING, 3, 2);
			buttonBar.setLayout(layou);
		}
		return buttonBar;
	}

	/**
	 * @return getTopPane
	 * */
	protected Component getTopPane() {
		return getButtonBar();
	}
	
	/**
	 * @return getCenterPane
	 * */
	protected Component getCenterPane() {
		return null;
	}

	/**
	 * @return getBottomPane If is not created, not layout to this page.
	 * */
	protected Component getBottomPane() {
		return null;
	}
	
	/**
	 * @return getBottomPane If is not created, not layout to this page.
	 * */
	protected Component getLeftPane() {
		return null;
	}
	
	/**
	 * @return getBottomPane If is not created, not layout to this page.
	 * */
	protected Component getRightPane() {
		return null;
	}
	
	/** get the Id. */
	public String getPageId() {
		return this.getClass().getName();
	}

	/** get the title. */
	public String getPageName() {
		return this.getClass().getSimpleName();
	}

	/** dispose this page. */
	public void disposePage() {
		// remove IPassbookObserver
		IPassbookObserver.getInstance().removeIPassbookListener(this);
	}

	@Override
	public boolean isDefaultPage() {
		return isDefaultPage;
	}

	@Override
	public void setDefaultPage(boolean bool) {
		isDefaultPage = bool;
	}
	
	@Override
	public void update(IPassbookEvent event) {
		// TODO Auto-generated method stub
		
	}

}
